package com.tangdi.test;

import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.IOException;

import javax.print.PrintService;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
import org.apache.pdfbox.printing.PDFPageable;
import org.apache.pdfbox.printing.PDFPrintable;
import org.apache.pdfbox.printing.Scaling;

public class PrintWork {
/*    public static PDDocument document;
    public static void print(File file) throws IOException, PrinterException {
            PDDocument document = PDDocument.load(file);
            print(document);
            document.close();
    }*/
/*    private static void print(PDDocument document) throws IOException, PrinterException
    {
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPageable(new PDFPageable(document));
        job.print();
    }*/
    
    public static void main(String[] args) throws InvalidPasswordException, IOException, PrinterException{
/*    	// 使用打印机的名称
		String printName = "Win32 Printer : Microsoft Print to PDF";
		String pdfPath = "D:\test.pdf";
        File file = new File(pdfPath);
		// 读取pdf文件
        PDDocument document = PDDocument.load(file);
		// 创建打印任务
        PrinterJob job = PrinterJob.getPrinterJob();
        // 遍历所有打印机的名称
        for (PrintService ps : PrinterJob.lookupPrintServices()) {
            String psName = ps.toString();
			// 选用指定打印机
            if (psName.equals(printName)) {
                job.setPrintService(ps);
                break;
            }
        }
 
        job.setPageable(new PDFPageable(document));
 
        Paper paper = new Paper();
		// 设置打印纸张大小
        paper.setSize(598,842); // 1/72 inch
		// 设置打印位置 坐标
        paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight()); // no margins
        // custom page format
        PageFormat pageFormat = new PageFormat();
        pageFormat.setPaper(paper);
        // override the page format
        Book book = new Book();
        // append all pages 设置一些属性 是否缩放 打印张数等
        book.append(new PDFPrintable(document, Scaling.ACTUAL_SIZE), pageFormat, 1);
        job.setPageable(book);
		// 开始打印
        job.print();*/
 
      
        Runtime.getRuntime().exec("cmd.exe /C start acrord32 /t " + "F:/EclipseWorkspace/workspaces/JHDFGZReportManage/WebContent/report_File/201905/pdf/单位统发工资转账通知书/201905_转账通知书_142001_南京市统计局.pdf");
    }
}
